<script setup>
import {ref} from "vue";
import {setting, updateSetting} from "../api/systemSetting.js";
import {toast} from "vue3-toastify";

const form = ref({})
const getSetting = () => {
  setting().then(res => {
    if (res.code === 200) {
      form.value = res.data;
    } else {
      toast.error(res.msg);
    }
  })
}
getSetting();

const loading = ref(false);
const update = () => {
  loading.value = true;
  updateSetting(form.value).then(res => {
    loading.value = false;
    if (res.code === 200) {
      toast.success(res.msg);
    } else {
      toast.error(res.msg);
    }
  }).catch(e => {
    loading.value = false;
    console.log(e);
  })
}

</script>

<template>
  <v-form ref="formRef">
    <v-container max-width="96%">
      <v-row class="mt-1">
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="tmdb Api Key"
              hint="请到tmdb官网注册申请"
              v-model="form.tmdbAPIKey"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="tmdb基础地址"
              hint="tmdb基础地址，正常情况下不用动"
              v-model="form.tmdbBaseUrl"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="种子保存路径"
              hint="种子保存路径"
              v-model="form.torrentSavePath"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="种子服务器"
              hint="种子服务器"
              v-model="form.torrentAnnounce"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col cols="12" md="6">
          <v-radio-group label="成人标识" v-model="form.tmdbAdult" inline>
            <v-radio label="打开" :value="true"></v-radio>
            <v-radio label="关闭" :value="false"></v-radio>
          </v-radio-group>
        </v-col>
        <v-col cols="12" md="6">
          <v-radio-group label="自动创建季目录" v-model="form.autoCreateSeasonFolder" inline>
            <v-radio label="打开" :value="true"></v-radio>
            <v-radio label="关闭" :value="false"></v-radio>
          </v-radio-group>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电影文件名格式"
              hint="电影文件名格式，匹配字符固定，可调整顺序"
              v-model="form.fileNameMovie"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电视剧文件名格式"
              hint="电视剧文件名格式，匹配字符固定，可调整顺序"
              v-model="form.fileNameTv"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电视剧文件夹格式"
              hint="电视剧文件夹格式，匹配字符固定，可调整顺序"
              v-model="form.folderNameTv"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季电视剧文件夹格式"
              hint="单季电视剧文件夹格式，匹配字符固定，可调整顺序"
              v-model="form.folderNameTvSeason"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季单集电视剧文件夹格式"
              hint="单季单集电视剧文件夹格式，匹配字符固定，可调整顺序"
              v-model="form.folderNameTvSeasonEpisode"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电影主标题格式"
              hint="电影主标题格式，匹配字符固定，可调整顺序"
              v-model="form.mainTitleMovie"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电影主标题格式"
              hint="电影主标题格式，匹配字符固定，可调整顺序"
              v-model="form.mainTitleMovie"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电视剧主标题格式"
              hint="电视剧主标题格式，匹配字符固定，可调整顺序"
              v-model="form.mainTitleTv"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季电视剧主标题格式"
              hint="单季电视剧主标题格式，匹配字符固定，可调整顺序"
              v-model="form.mainTitleTvSeason"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季单集电视剧主标题格式"
              hint="单季单集电视剧主标题格式，匹配字符固定，可调整顺序"
              v-model="form.mainTitleTvSeasonEpisode"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电影副标题格式"
              hint="电影副标题格式，匹配字符固定，可调整顺序"
              v-model="form.subTitleMovie"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="电视剧副标题格式"
              hint="电视剧副标题格式，匹配字符固定，可调整顺序"
              v-model="form.subTitleTv"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季电视剧副标题格式"
              hint="单季电视剧副标题格式，匹配字符固定，可调整顺序"
              v-model="form.subTitleTvSeason"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="单季单集电视剧副标题格式"
              hint="单季单集电视剧副标题格式，匹配字符固定，可调整顺序"
              v-model="form.subTitleTvSeasonEpisode"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col cols="12" md="12">
          <v-combobox
              v-model="form.source"
              :items="form.source"
              label="来源"
              variant="outlined"
              chips
              closable-chips
              multiple
          >
            <template v-slot:chip="{ props, item }">
              <v-chip v-bind="props" draggable>
                <strong>{{ item.raw }}</strong>&nbsp;
              </v-chip>
            </template>
          </v-combobox>
        </v-col>
        <v-col cols="12" md="12">
          <v-combobox
              v-model="form.team"
              :items="form.team"
              label="小组"
              variant="outlined"
              chips
              closable-chips
              multiple
          >
            <template v-slot:chip="{ props, item }">
              <v-chip v-bind="props" draggable>
                <strong>{{ item.raw }}</strong>&nbsp;
              </v-chip>
            </template>
          </v-combobox>
        </v-col>
        <v-col cols="12" md="12">
          <v-combobox
              v-model="form.videoFormatList"
              :items="form.videoFormatList"
              label="支持视频格式"
              variant="outlined"
              chips
              closable-chips
              multiple
          >
            <template v-slot:chip="{ props, item }">
              <v-chip v-bind="props" draggable>
                <strong>{{ item.raw }}</strong>&nbsp;
              </v-chip>
            </template>
          </v-combobox>
        </v-col>
        <v-col
            cols="12"
            md="12"
        >
          <v-text-field
              label="Auto Feed地址格式"
              hint="Auto Feed地址格式，一般勿动"
              v-model="form.autoFeedLink"
              variant="outlined"
              clearable
              auto-grow
          >
          </v-text-field>
        </v-col>
        <v-col cols="12" md="12">
          <div class="d-flex flex-column">
            <v-btn
                class="mt-4"
                color="success"
                block
                @click="update"
                :loading="loading"
            >
              保存配置
            </v-btn>
          </div>
        </v-col>
      </v-row>
    </v-container>
  </v-form>
</template>

<style scoped>

</style>